
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/29/2011 15:56:24
-- Generated from EDMX file: E:\IFCHEUNG\IFPRJ\IFPRJ.EF.Model\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [IFDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ModulePost_Catory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[News_Catory] DROP CONSTRAINT [FK_ModulePost_Catory];
GO
IF OBJECT_ID(N'[dbo].[FK_Post_CatoryPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[News] DROP CONSTRAINT [FK_Post_CatoryPost];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[News]', 'U') IS NOT NULL
    DROP TABLE [dbo].[News];
GO
IF OBJECT_ID(N'[dbo].[News_Catory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[News_Catory];
GO
IF OBJECT_ID(N'[dbo].[Pages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Pages];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Post'
CREATE TABLE [dbo].[Post] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title_Long] nvarchar(max)  NOT NULL,
    [Title_Short] nvarchar(max)  NULL,
    [Description] nvarchar(max)  NULL,
    [Context] nvarchar(max)  NULL,
    [Date_Post] datetime  NOT NULL,
    [CatoryID] int  NULL,
    [Src] nvarchar(max)  NULL,
    [Pic_Related] nvarchar(max)  NULL,
    [Date_Lastupdated] datetime  NULL,
    [User_firstAdd] nvarchar(max)  NULL,
    [User_Lastupdate] datetime  NULL,
    [SearchText] nvarchar(max)  NULL,
    [Hits] int  NULL,
    [Post_CatoryID] int  NOT NULL
);
GO

-- Creating table 'Post_Catory'
CREATE TABLE [dbo].[Post_Catory] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [ParentID] int  NULL,
    [SortID] int  NULL,
    [ModuleID] int  NOT NULL
);
GO

-- Creating table 'Module'
CREATE TABLE [dbo].[Module] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Action] nvarchar(max)  NULL,
    [Controller] nvarchar(max)  NULL,
    [Area] nvarchar(max)  NULL,
    [ChildrenId] int  NULL,
    [AddDateTime] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Post'
ALTER TABLE [dbo].[Post]
ADD CONSTRAINT [PK_Post]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Post_Catory'
ALTER TABLE [dbo].[Post_Catory]
ADD CONSTRAINT [PK_Post_Catory]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Module'
ALTER TABLE [dbo].[Module]
ADD CONSTRAINT [PK_Module]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ModuleID] in table 'Post_Catory'
ALTER TABLE [dbo].[Post_Catory]
ADD CONSTRAINT [FK_ModulePost_Catory]
    FOREIGN KEY ([ModuleID])
    REFERENCES [dbo].[Module]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ModulePost_Catory'
CREATE INDEX [IX_FK_ModulePost_Catory]
ON [dbo].[Post_Catory]
    ([ModuleID]);
GO

-- Creating foreign key on [Post_CatoryID] in table 'Post'
ALTER TABLE [dbo].[Post]
ADD CONSTRAINT [FK_Post_CatoryPost]
    FOREIGN KEY ([Post_CatoryID])
    REFERENCES [dbo].[Post_Catory]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Post_CatoryPost'
CREATE INDEX [IX_FK_Post_CatoryPost]
ON [dbo].[Post]
    ([Post_CatoryID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------